using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class MainScenPanel : MonoBehaviour
{
    [SerializeField] private Text TokenNum;
    [SerializeField] private GameObject TokenGetPanel;
    public void Awake()
    {
        if (!PlayerPrefs.HasKey("MainsToken"))
        {
            PlayerPrefs.SetInt("MainsToken", 3);
        }
        RefreshToken();
    }

    public void GameStart()
    {
        if (PlayerPrefs.GetInt("MainsToken")>0)
        {
            PlayerPrefs.SetInt("MainsToken", PlayerPrefs.GetInt("MainsToken") - 1);
            RefreshToken();
            SceneManager.LoadScene("MainGame");
        }
        else
        {
            TokenGetPanel.SetActive(true);
        }
    }

    void RefreshToken()
    {
        TokenNum.text = PlayerPrefs.GetInt("MainsToken").ToString();
    }

    public void AdsForGetToken()
    {
        if (AdsManager.Instance.rewardeVideoId!="0")
        {
            AdsManager.Instance.RewardVideoAd(b =>
            {
                if (b)
                {
                    PlayerPrefs.SetInt("MainsToken", PlayerPrefs.GetInt("MainsToken") + 3);
                    RefreshToken();
                }
            });
        }
        else
        {
            PlayerPrefs.SetInt("MainsToken", PlayerPrefs.GetInt("MainsToken") + 3);
            RefreshToken();
        }
    }
}
